package edu.udo.sopra10.chaturaji.entities.terminationconditions;

import edu.udo.sopra10.chaturaji.entities.Game;
import edu.udo.sopra10.chaturaji.entities.Player;

/**
 * {@link Game} termination after a certain amount of points has been gained by
 * a player or {@link TotalElimination} occurs.
 * 
 * @author Simon Dierl
 */
public final class ScoreLimit extends Limit {
	/**
	 * Create a new {@link ScoreLimit} for the specified {@link Game}.
	 * 
	 * @param game
	 *            the terminated game, may be {@code null} if not created.
	 * @param limit
	 *            the point limit, must be {@code > 0}.
	 */
	public ScoreLimit(final Game game, final int limit) {
		super(game, limit);
	}

	@Override
	public boolean isGameTerminated() {
		if (super.isGameTerminated()) {
			return true;
		}
		for (final Player player : game.getPlayers()) {
			if (player.getScore() >= limit) {
				return true;
			}
		}
		return false;
	}
}
